package com.caigou.util;

import com.caigou.enums.FailResultEnum;
import com.caigou.enums.ResponseEnum;
import com.caigou.enums.SuccessResultEnum;
import lombok.Data;

@Data
//@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Result<T> {
    private Integer status;
    private String message;
    private T data;

    public Result() {
    }


    public Result(Integer status, String message) {
        this.status = status;
        this.message = message;
    }

    public Result(Integer status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data =  data;
    }


    public static <T> Result<T> success() {
        return new Result<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage());
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMessage(),data);
    }

    public static <T> Result<T> success(ResponseEnum responseEnum) {
        return new Result<>(responseEnum.getCode(), responseEnum.getMessage());
    }

    public static <T> Result<T> success(ResponseEnum responseEnum, T data) {
        return new Result<>(responseEnum.getCode(), responseEnum.getMessage(),data);
    }


    public static <T> Result<T> success(SuccessResultEnum responseEnum) {
        return new Result<>(responseEnum.getCode(), responseEnum.getMessage());
    }

    public static <T> Result<T> success(SuccessResultEnum responseEnum, T data) {
        return new Result<>(responseEnum.getCode(), responseEnum.getMessage(),data);
    }

    public static <T> Result<T> error(T data) {
        return new Result<>(ResponseEnum.SERVER_ERROR.getCode(), ResponseEnum.SERVER_ERROR.getMessage(),data);
    }

    public static <T> Result<T> error(ResponseEnum responseEnum) {
        return new Result<>(responseEnum.getCode(), responseEnum.getMessage());
    }

    public static <T> Result<T> error(ResponseEnum responseEnum, T data) {
        return new Result<>(responseEnum.getCode(), responseEnum.getMessage(),data);
    }



    public static <T> Result<T> error(FailResultEnum responseEnum) {
        return new Result<>(responseEnum.getCode(), responseEnum.getMessage());
    }

    public static <T> Result<T> error(FailResultEnum responseEnum, T data) {
        return new Result<>(responseEnum.getCode(), responseEnum.getMessage(),data);
    }

    public static <T> Result<T> error(String message, T data) {
        return new Result<>(ResponseEnum.SERVER_ERROR.getCode(), message,data);
    }

    public static <T> Result<T> error(Integer code, String message, T data){
        return new Result<>(code, message, data);
    }

    public static <T> Result<T> custom(Integer code, String message, T data){
        return new Result<>(code, message, data);
    }

}
